********************************************************************
*                               U.C.D.M                            *
*                                                                  *
*               Frequently asked questions from coders             *
*                                                                  *
********************************************************************

This textfile deals with problems that coders might have
when trying to do something more than the usual with UCDM.



Question:

 What is this TRASH-replay that is mentioned everywhere in the files?
 
Answer:

 The idea with TRASH-replay is simpel. In a lot of games and demos you 
 want everything to run in full framerate (usually 50 Hz in Europe and 
 60 Hz in USA) to make movement so smoth as possible. If the 
 screenupdate is slowed down for just a fraction of a second the 
 spectator will imediately notice that the sprites "jerked" a bit. The 
 problem is often that you most of the time have a lot of 
 processing-power left, but at some crucial point in the game/demo all 
 the processing-power is needed. This is a real waste, you can't add
 anything since it would make the screenupdate to slow at that crucial
 point, but in average you maybe have as much as 40% of the power 
 left. Just think of what can be done with that power...
 
 TRASH-replay takes use of that power by using it for music.
 The name comes from the fact that it takes use of all "trashed" 
 pieces of processing-power.
 The technique is also very simple. Normally you put the replayroutine 
 on a timer. When you are using TRASH-replay you put the rest of the 
 game/demo on the VBL-interrupt (or another timer) and lets the 
 replayroutine run in an eternal loop in the background. By giving 
 it a buffer to put the result in before it is used it doesn't matter 
 if it doesn't get all the time it needs every screenupdate, as long 
 as it is given a bit more time than it needs earlier so the buffer is 
 filled up. This makes the player dependent on the average amount of 
 processing-time instead of the maximum. The bigger buffer you give 
 it, the longer you can keep it starving before it starts to sound bad 
 (you will hear the player repeat the last played piece if nothing is 
 left in the buffer and it isn't given the needed time).
 
 However, there are some disadvantages with this method. First of all 
 it takes some more memory. Then you might have problems with 
 interrupts and players that use the blitter since the blitter might 
 be called anywhere you have time left and not just at some certain 
 point of every screenupdate.
 But the problem that is most disturbing is the fact that the music is 
 updated quite a long time before it is played. If you want to use the 
 8-command it will say that you are at some certain position in the 
 song when it is updated, which might be quite a while before it 
 actually is played. If you want to add soundeffects (as described 
 below) it might take quite a while before they are played since there
 might be a lot of data in the buffer.
 

Question:

 Do I have to re-initialise the player if I want to change the song?
 It just takes the computer an awful lot of time to reinitialise everything.

Answer:

 No, the only thing you have to reinitialise is the feeder.
 This might take a few VBL:s if the song is long and there's always
 a risk that the soundchip sounds strange during that time so I recomend
 you the following process:

 1. Keep the player running as normal in the background, but disable the
    driver.
    
 2. Clear 8 longwords starting at byte-offset 268 in the player
    (i.e. #PLAYER+268). These longwords controls the volume and by setting
    them to zero we keep the Player updating silence during that time.

 3. Reinitialise the feeder for the new song using "jsr FEEDER" (with 
    a0 pointing at the samplebank and a1 pointing at the new song).
   
 4. Start the feeder again.


Question:
 Can I use the same feeder with many different players in the same 
 program?
 
Answer:
 Yes, you can. The easiest way to do this is by following these steps:
 
 1. Call Player+8 to turn the soundchip off and make sure that neither 
    the player of feeder runs anymore.
    
 2. Copy the new driver to the same adress as the previously run 
 player (#PLAYER). If the new player is bigger than the previous you 
 need to have reserved some empty space after the previous player.
 
 3. Re-initialise both the player and the driver, but first make sure 
 that the reserved area for the older player is big enough for the new 
 one!
 
 You might get some problems if you want to use a voiceset that has been
 manipulated to suit the previous player.


Question:

 Can I make the Player play some samples of my choice in the middle of
 a song ?  It really would be useful if I could include soundeffects into
 the song during play. 

Answer:

 Yes, you can make the player play a soundeffect on one or more voices
 in the middle of a song, but then you have to know a few things about
 the UCDM-Player-interface:

 For every voice there is 5 longwords controling the sound. They are
 named FREQ, SAM_PEK, SAM_END, END_SUB, VOL. 
 
 FREQ:  This longword determines the frequency that the sample is played at.
        Since UCDM is working with frequencytables of varying size the
        procedure of setting the correct frequency is a bit complicated
        and the values to be entered varies a lot depending on the "TONES"
        settings and basefrequency, but here's a table for you:
                
        VALUE      16 kHz basefreq.  20 kHz basefreq.  25 kHz basefreq.
        -----      ----------------  ----------------  ----------------
         0              4 293 Hz          5 000 Hz        6 250 Hz
         6*X            6 084 Hz          7 085 Hz        8 857 Hz
         9*X            7 234 Hz          8 425 Hz       10 532 Hz
        12*X            8 586 Hz         10 000 Hz       12 500 Hz
        15*X           10 208 Hz         11 889 Hz       14 861 Hz
        18*X           12 168 Hz         14 172 Hz       17 714 Hz
        21*X           14 468 Hz         16 851 Hz       21 063 Hz
        24*X           17 172 Hz         20 000 Hz       25 000 Hz
        27*X           20 416 Hz         23 778 Hz       29 722 Hz
        30*X           24 337 Hz         28 345 Hz       35 431 Hz
        
        X=(TONES+1)*4

        So if you for example want to play a sample in 10 kHz when you
        are using 20 kHz basefrequency and TONES is set to 5 you simply
        put 288 into FREQ for the correct channel.

	You don't have to stick strictly to the table, you can multiply 
	X with any value between 0 and 35, but it should give you a clue
	about where you have the different frequencies.
	
SAM_PEK: This is simply the samplepointer. If you want to play a sample
         starting on adress $78f3e you simply put that value here.
         this pointer is then incremented every time you call the player,
         showing the sample position.
         	 
SAM_END: This longword shall point at the end of the sample, or the 
         loop-position (if the sample is looping). SAM_END is compared
         against SAM_PEK once every call, if SAM_END is lower than 
         SAM_PEK the sample is looped or stopped playing. This means 
         that SAM_END actually can be passed with almost 1 kb (at 50 
         kHz replay) before the sample is stopped. This means that you 
         have to make sure that there is at least 1000 bytes 
         containing zero after the end of the sample or, if it is 
         looped, containing a copy of the first 1000 bytes after the 
         loop-destination. I used 50 kHz for an example, but the area 
         never needs to be bigger than 1/50 of the replay frequency 
         (that is the replay frequency of the sample, not the Player).
         
END_SUB: Setting this longword to 0 will cause the sample to stop 
         play after having reached SAM_END. Any other value will cause
         the sample to loop back that amount of bytes.
         
         After a sample is stopped is SAM_PEK and SAM_END put to 
         the same value.
         
VOL:     The third byte in this longword contains the volume in the 
         normal soundtracker way (0-64). The other bytes in this 
         longword must be set to zero.
         
         Organization of the longwords
         -----------------------------
         
         Since UCDM is prepared for 16-voices there are totally 16*5 
         longwords for controling the sound, starting at byte 12 from 
         the start of the player. First comes FREQ for all 16 voices,
         then comes SAM_PEK, SAM_END, END_SUB and VOL.
         
         I would also like to mention that the channels are a bit 
         moved (compared to The Octalyser and other trackers). Voice 3 
         and 4 has swapped places, aswell as voice 7 and 8 when 
         playing 8 channels. This makes all odd channels play on the 
         left speaker and all even channels play on the right speaker.
         
         Some players needs to have the samples "downshifted" before 
         they can play them, so if it sounds bad you should try to 
         shift down the samples one or two steps to the right using 
         the following routine:
         
              move.b    (a0),d0      ; get a byte from the sample 	
              ext.w     d0           ; sign extend it.
              lsr.w     #1,d0        ; shift it down one or two steps
              move.b    d0,(a0)+     ; put it back.

         There is a word in the player beginning at byte-offset 350 
         (i.e. #PLAYER+350)  telling you how many bits the samples 
         shall consist of. If it says 8 you shouldn't shift down your 
         samples, if it says 7 you should shift them down one step 
         etc.

         I recommend you to put the samples on a free track in the 
         song if it is possible, if not you should follow the 
         following process: 
                          
         1. Call the Feeder as usual.
         
         2. Make a copy of FREQ, SAM_PEK, SAM_END, END_SUB and VOL for 
         the voices you want to put soundeffects on.
         
         3. Initialize FREQ, SAM_PEK, SAM_END, END_SUB and VOL for 
         the soundeffects.
         
         4. Call the Player as usual.
         
         5. Save down the longwords for the soundeffects and put back
         the saved ones.
         
         6. Now you can repeat step 1 through 6 as long as the 
         soundeffect is playing. The easiest way to check if the 
         soundeffect still is playing is to test if SAM_END has a new 
         value.
         
         7. When you have finished playing the sample put back FREQ 
         and VOL. Then check if the voice should contain a looping 
         sample (by testing if END_SUB should be zero), if it should 
         you better put back SAM_PEK, SAM_END and END_SUB so the 
         sample can continue to play. If it shouldn't loop you better 
         not put it back unless the soundeffect was very short, 
         because it often sounds a lot better if an instrument just 
         disappers than plays out of sync.

         If you are really serious about using UCDM in games you 
         could contact me (Blade). I have a few players with 
         additional voices for soundeffects, they doesn't take much 
         more time than a player without them as long as the 
         soundeffects doesn't need volumecontrol or more than one 
         replay frequency. Please remember that you need a licence if 
         you want to use UCDM in commercial products.


IF YOU HAVE ANY PROBLEMS OR BUGREPORTS YOU CAN REACH ME (BLADE) BY:

1. Leave a message on The Toxic BBS (+46-(0)13-128907) to "BLADE".

2. Sending me E-mail: blade@lysator.liu.se
   Though I don't know how long I can keep this adress (I'm quitting
   school in order to start my own software house).
   
3. Sending me mail at the following adress before the end of August -94.

                   THE OCTALYSER TEAM
                   Bjrnkrrsgatan 7A.12
                   582 51  LINKPING
                   SWEDEN

4. Calling this number in August -94.

         +46-(0)13-176574
         
As you probably have guessed I'm moving to another appartment rather 
soon and I don't know the new adress or telephonenumber yet. If you 
want to reach me after the end of August you have to write Christian 
(Code/TBL) instead and he will send the letter to me.
 
Greetings

Tord Jansson (Blade/New Core)
         